package com.oepm.biz.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.oepm.biz.ResultBiz;
import com.oepm.dao.entity.QueryInfo;
import com.oepm.dao.entity.ResultPo;
import com.oepm.dao.entity.UserVo;
import com.oepm.dao.mapper.ResultMapper;
import com.oepm.vo.DataVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ResultBizImpl implements ResultBiz {

    @Resource
    private ResultMapper resultMapper;


    @Override
    public int updateResult(ResultPo resultPo) {
        return resultMapper.updateResult(resultPo);
    }

    @Override
    public ResultPo queryAddressByPid(String pid) {
        return resultMapper.queryAddressByPid(pid);
    }

    @Override
    public String queryUserIdByPid(String pid) {
        return resultMapper.queryUserIdByPid(pid);
    }

    @Override
    public DataVo<ResultPo> selectResultsStu(String userId, QueryInfo queryInfo) {
        PageHelper.startPage(queryInfo.getPagenum(),queryInfo.getPagesize());
        List<ResultPo> resultPos = resultMapper.selectResultsStu(userId);
        PageInfo<ResultPo> pi = new PageInfo<>(resultPos);

        return new DataVo(pi.getTotal(),pi.getList());
    }

    @Override
    public List<ResultPo> selectResults(String pname) {
        return resultMapper.selectResults(pname);
    }

    @Override
    public DataVo<ResultPo> selectResultAll(QueryInfo queryInfo) {
        PageHelper.startPage(queryInfo.getPagenum(),queryInfo.getPagesize());
        List<ResultPo> resultPos = resultMapper.selectResultAll();
        PageInfo<ResultPo> pi = new PageInfo<>(resultPos);

        return new DataVo(pi.getTotal(),pi.getList());
    }
}
